package com.seveneight.baijiesteward.ui.user.model;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.reflect.TypeToken;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BankBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.ui.user.contract.GetBankListContract;
import com.seveneight.baijiesteward.utils.LogUtil;

import java.util.Arrays;
import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/17.
 */

public class GetBankListModel extends BaseModel implements GetBankListContract.GetBankModel {

    @Override
    public void getBankList(Context context, RequestBody body, MyCallBack<List<BankBean>> myCallBack) {
        RetrofitFactory.getInstence().API().getBankList(body)
                .compose(this.<BaseEntity<AnyBean>>setThread())
                .subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        LogUtil.d("banklist:" + t.getData().toString());
                        if(t.getData().getBankData()!=null){
                            List<BankBean> data=JSON.parseArray(t.getData().getBankData(),BankBean.class);
                            myCallBack.onSuccess(data);
                        }
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
